package scut.facerecognition.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import scut.facerecognition.entity.dto.MessageUserDTO;
import scut.facerecognition.entity.pojo.Message;
import scut.facerecognition.entity.pojo.User;
import scut.facerecognition.result.Result;
import scut.facerecognition.service.MessageService;

import java.util.List;

@Slf4j
@RestController("messageController")
@RequestMapping("/chat")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 获取该用户和另一用户的历史消息
     */
    @PostMapping("/historyMessage")
    public Result<List<Message>> getHistoryMessages(@RequestBody MessageUserDTO messageUserDTO) {
        List<Message> list=messageService.getHistoryMessages(messageUserDTO);
        return Result.success(list);
    }

    /**
     * 获取和这位用户有过聊天的用户
     */
    @GetMapping("/getInterlocutor/{userId}")
    public Result<List<User>> getInterlocutor(@PathVariable long userId) {
        List<User> userList=messageService.getInterlocutor(userId);
        return Result.success(userList);
    }

}
